package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.Cart;
import com.guigu.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/cart/")
public class CartController {

    @Autowired
    CartService cartService;

    //分类分页
    @GetMapping("allCart.action")
    public Page<Cart> allCart(Cart cart,
            @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                              @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize){
        return cartService.allCart(cart,pageno,pagesize);
    }

    //批量删除购物车
    @PostMapping("delCarts.action")
    public Map delCarts(@RequestBody List<Integer> ids){
        return cartService.delCarts(ids);
    }

    //根据多个id查询购物车
    @PostMapping("cartIds.action")
    public List<Cart> queryCartsByIds(@RequestBody List<Integer> cartIds) {
        return cartService.queryCartsByIds(cartIds);
    }

    //根据商品id添加一条购物车记录并返回购物车
    @PostMapping("cart.action")
    public Map addCartByShopId(@RequestBody Cart cart) {
        return cartService.addCartByShopId(cart);
    }

    //添加订单前计算
    @PutMapping("changeNum.action")
    public Map changeNum(@RequestBody Cart cart){
        return cartService.changeNum(cart);
    }

    @GetMapping("querygwCartnum.action/{uid}")
    public int querygwCartnum(@PathVariable int uid){
        return cartService.querygwCartnum(uid);
    }
}
